layui.use('layedit', function(){
    var layedit = layui.layedit
        ,$ = layui.jquery;

    //构建一个默认的编辑器
    var index = layedit.build('LAY_demo1');

    //编辑器外部操作
    var active = {
        content: function(){


            $.ajax({
                type: 'POST',
                url: "/news/addNewSelectItems",
                dataType:"json",
                async: false,
                data:{
                    range: $("#select-option option:selected").val(),
                    title: $("#title").val(),
                    introduction: $("#introduction").val(),
                    count: layedit.getContent(index),
                    ggType: $('#type-option').val(),

                },
                success: function (message) {
                    if(message.code==0){
                        layer.msg('增加成功');
                        console.log("增加成功")
                        window.location.href="./news.html"
                        console.log("dasdasdas")
                        return
                    }else {
                        console.log("增加失败")
                        layer.msg('增加失败，请稍后重试！');
                        console.log("ddasdasds")
                        return
                    }
                }
            })

            // console.log($("#select-option option:selected").val())
            //
            //
            //
            //
            // alert(layedit.getContent(index)); //获取编辑器内容
        }
    };

    $('.site-demo-layedit').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });

    //自定义工具栏
    layedit.build('LAY_demo2', {
        tool: ['face', 'link', 'unlink', '|', 'left', 'center', 'right']
        ,height: 100
    })
});